package com.java8.function;

import java.util.function.BiConsumer;
import java.util.function.Function;

/**
 * @Description: 函数编程
 * @Author: whp
 * @Date: 2021-02-08 15:14
 */
public class Operation {
    public static int addOne(int a){
        return a+1;
    }

    /*
     * @Description: 该方法第二个参数接受一个function 类型行为，让后apply，对参数a执行这个行为
     * @Param: [a, action]
     * @return int
     **/
    public final static int oper(int a , Function<Integer,Integer> action){
        return action.apply(a);
    }
    public final static BiConsumer<Integer, Integer> bicomsumer(int a, int b){
        System.out.println(a+b);
        return null;
    }

    public final static void comsumer(int a, BiConsumer<Integer,Integer> action){
         action.accept(a,a);
    }

    public static void main(String[] args) {
        int x=2;
       // int y=oper(x,Operation::addOne); // 可以传入lamda 表达式函数名称
       // int y=oper(x,t->t+3);
        int y=oper(x,t->addOne(x));

        System.out.println(x);
        System.out.println(y);
        System.out.println("------------");

        comsumer(x,bicomsumer(x,x+1));
    }
}
